package com.sino.second.business.service;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import com.opensymphony.xwork2.ActionContext;
import com.sino.bean.Basicinfo;
import com.sino.bean.TblZhuanjiarukuxinxibiao;
import com.sino.model.ExpertModel;
import com.sino.second.bean.SysXmpsdj;
import com.sino.second.bean.SysXmpszb;
import com.sino.second.bean.TblSystemparam;
import com.sino.second.bean.TblXmfs2;
import com.sino.second.bean.TblXmjg1;
import com.sino.second.bean.TblXmjg2;
import com.sino.second.bean.TblXmpfbz;
import com.sino.second.bean.TblZjpsfp;
import com.sino.second.business.IReviewService;
import com.sino.second.dao.IExpertsReviewDAO;
import com.sino.second.dao.IZjpsfpDAO;
import com.sino.second.dao.hibernate.BaseDataDAO;
import com.sino.second.model.ExpertsReviewModel;
import com.sino.second.model.ExpertsReviewModel2;
import com.sino.second.model.XmReviewResults;
import com.sino.second.model.XmReviewResults1;
import com.sino.second.model.XmReviewResults2;
import com.sino.second.model.XmReviewResults3;
import com.sino.second.model.XmpsdjModel;
import com.sino.second.util.BeanAndModelConverter;
import com.sino.util.DateUtils;
import com.sino.util.SysParameter;
import com.sino.util.page.PagerModel;

public class Review2ServiceImpl implements IReviewService {
	private IExpertsReviewDAO review2DAO;// ================复审DAO

	private IExpertsReviewDAO review1DAO;

	private BaseDataDAO baseDataDAO = null;// 基础类数据DAO

	private IZjpsfpDAO zjpsfpDAO;// 引入zjpsfpDAO

	/**
	 * 初审专家评分VO转PO
	 */
	public Object voToPo(ExpertsReviewModel erm) {
		ExpertsReviewModel2 erm2 = (ExpertsReviewModel2) erm;
		TblXmfs2 tx2 = new TblXmfs2();
		if (erm2.getId() == null || erm2.equals("")) {

		} else {
			tx2.setId(erm2.getId());
		}
		Basicinfo bi = new Basicinfo();
		bi.setZlid(erm2.getBasicInfoModel().getZlid());
		tx2.setBasicinfo(bi);
		TblZhuanjiarukuxinxibiao tzjrk = new TblZhuanjiarukuxinxibiao();
		tzjrk.setFBh(erm2.getExpertModel().getFBh());
		tx2.setTblZhuanjiarukuxinxibiao(tzjrk);
		tx2.setFzqz(erm2.getFzqz());
		tx2.setState(erm2.getState());
		SysXmpszb sx = new SysXmpszb();
		sx.setId(erm2.getXmpszbModel().getId());
		tx2.setSysXmpszb(sx);
		TblXmpfbz txf = new TblXmpfbz();
		txf.setId(erm2.getXmpsbzModel().getId());
		SysXmpsdj sxd = new SysXmpsdj();
		sxd.setId(erm2.getJydj().getId());
		tx2.setSysXmpsdj(sxd);
		tx2.setTblXmpfbz(txf);
		tx2.setXmfs(erm2.getXmfs());
		tx2.setYear(SysParameter.CURRENT_YEAR);
		tx2.setPsrq(DateUtils.getSystemDate());

		return tx2;
	}

	public List<XmReviewResults> findReviewResultsList(String hqlWhere) {
		List<TblXmjg2> tx2List = this.getReview2DAO().findReviewResultsList(
				hqlWhere);
		List<XmReviewResults> xrrList = new ArrayList<XmReviewResults>();
		for (TblXmjg2 tx2 : tx2List) {
			xrrList.add(BeanAndModelConverter
					.getXmReviewResults2ByTblXmjg2(tx2));
		}
		return xrrList;
	}

	public List findReviewXmListByZjId(Integer zjid, String hqlWhere) {
		List<Object[]> zjoList = this.getReview2DAO().findReviewXmListByZjId(
				zjid, hqlWhere);
		List<ExpertsReviewModel> ermList = new ArrayList<ExpertsReviewModel>();
		for (Object[] o : zjoList) {
			ExpertsReviewModel2 erm = new ExpertsReviewModel2();
			erm.setBasicInfoModel(BeanAndModelConverter
					.getBasicInfoModel((Basicinfo) o[0]));
			erm.setJydj(BeanAndModelConverter
					.getXmpsdjModelByXmpsdjBean((SysXmpsdj) o[1]));
			erm.setXmzf((Double) o[2]);
			erm.setFzqzzf((Double) o[3]);
			ermList.add(erm);

		}

		return ermList;
	}

	public int findReviewCount(String hqlWhere) {
		return this.getReview2DAO().findReviewCount(hqlWhere);
	}

	public Object findReviewResultsByZlid(String zjid) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 初审结果做为复审项目信息
	 */
	public List findReviewXmList(int firstRow, int maxRow, String xkId,
			String hqlWhere) {
		ExpertModel em = (ExpertModel) ActionContext.getContext().getSession()
				.get("expertModel");
		List<TblXmjg1> tx1List = this.getReview2DAO().findReviewXmList(
				firstRow, maxRow, xkId, hqlWhere);
		List<XmReviewResults1> xrr1List = new ArrayList<XmReviewResults1>();
		for (TblXmjg1 tx1 : tx1List) {
			XmReviewResults1 xrr1 = BeanAndModelConverter
					.getXmReviewResults1ByTblXmjg1(tx1);
			List<TblXmfs2> tx2List = this.getReview2DAO().findReviewsList(
					tx1.getBasicinfo().getZlid(), em.getFBh());
			if (tx2List != null && tx2List.size() >= 1) {
				xrr1.setCheckFlag(true);
			}
			if (tx1.getBasicinfo().getTxj2Set() != null
					&& tx1.getBasicinfo().getTxj2Set().size() >= 1) {
				xrr1.setCheckResults(true);
			}
			xrr1List.add(xrr1);
		}
		return xrr1List;
	}

	/**
	 * 专家列表记录数
	 * 
	 * @param xk
	 *            学科
	 * @param xkId
	 *            专利ID
	 * @return
	 */
	public int findReviewXmCount(String xkId, String hqlWhere) {
		return this.getReview2DAO().findReviewXmCount(xkId, hqlWhere);
	}

	public List<ExpertsReviewModel> findReviewXmListByZlId(String zlid,
			String hqlWhere) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<ExpertsReviewModel> findReviewsList(String zlid, Integer zjid) {
		List<TblXmfs2> tx2List = this.getReview2DAO().findReviewsList(zlid,
				zjid);
		List<ExpertsReviewModel> ermList = new ArrayList<ExpertsReviewModel>();
		for (TblXmfs2 txf2 : tx2List) {
			ermList.add((ExpertsReviewModel2) BeanAndModelConverter
					.getExpertsReviewModel2(txf2));
		}
		return ermList;
	}

	public ExpertsReviewModel poToVo(Object oepm) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 保存或者更新
	 */
	public void saveOrUpdateReviews(Object o) {
		List<ExpertsReviewModel2> ermList = (List<ExpertsReviewModel2>) o;
		List<TblXmfs2> tx1List = new ArrayList<TblXmfs2>();
		for (ExpertsReviewModel2 erm : ermList) {
			if (null != ermList.get(0).getJydj().getId()) {
				XmpsdjModel xdm = new XmpsdjModel();
				xdm.setId(ermList.get(0).getJydj().getId());
				erm.setJydj(xdm);
			}
			tx1List.add((TblXmfs2) this.voToPo(erm));
		}
		this.getReview2DAO().saveOrUpdateReviews(tx1List);

	}

	/**
	 * 根据条件查找复审分数表中的每个专家的评分情况列表
	 */
	public List<List<ExpertsReviewModel2>> findExpertReviewXmFsList(
			String hqlWhere) {
		List<Integer> expertIdList = this.getReview2DAO()
				.listReviewFsExpertIdList(hqlWhere);
		List<List<ExpertsReviewModel2>> basicInfoListList = new ArrayList<List<ExpertsReviewModel2>>();

		for (Integer expertId : expertIdList) {
			List<ExpertsReviewModel2> erModelList = new ArrayList<ExpertsReviewModel2>();
			Iterator it = this.getReview2DAO().listReviewXmIdList(expertId,
					hqlWhere).iterator();
			while (it.hasNext()) {
				Object[] result = (Object[]) it.next();
				ExpertsReviewModel2 erModel = new ExpertsReviewModel2();
				erModel.setBasicInfoId(result[0].toString());
				erModel.setFzqzzf(getTwoDecimal((Double) result[1]));
				erModel.setXmzf(getTwoDecimal((Double) result[2]));
				// System.out.println("------------------项目id：
				// "+erModel.getBasicInfoId());
				// System.out.println("权重总分： "+erModel.getFzqzzf());
				// System.out.println("-------------------------------------------");
				erModelList.add(erModel);
			}
			basicInfoListList.add(erModelList);
		}
		return basicInfoListList;
	}

	/**
	 * 根据条件查找复审分数表中的数据，并经过一定的运算返回复审分数model列表
	 */
	public List<ExpertsReviewModel2> findReviewXmFsList(String hqlWhere) {
		List<List<ExpertsReviewModel2>> erModelListList = this
				.findExpertReviewXmFsList(hqlWhere);
		List<ExpertsReviewModel2> erModelList = new ArrayList<ExpertsReviewModel2>();
		String hql = hqlWhere.replaceAll("xmfs", "xmjg");// 将hqlWhere中的表别名更改
		List<TblXmjg1> xmjg1List = this.review1DAO.findReviewXmJgList(hql);// 根据条件查找初审结果表中的项目信息
		int sortPosition = 0;
		int alreadyExpertCount = 0;
		int totalSortPosition = 0;
		double fzqzzf = 0.0;
		double xmzf = 0.0;
		for (TblXmjg1 xmjg1 : xmjg1List) {
			ExpertsReviewModel2 erModel = new ExpertsReviewModel2();// 新建一个ExpertsReviewModel2
			erModel.setBasicInfoId(xmjg1.getBasicinfo().getZlid());// 存入项目id
			erModel.setBasicInfoName(xmjg1.getBasicinfo().getName());// 存入项目名称
			erModel.setZlqr(xmjg1.getBasicinfo().getZlqr());// 存入专利权人
			erModel.setXkName(xmjg1.getBasicinfo().getXk().getName());// 存入学科名称
			alreadyExpertCount = 0;
			totalSortPosition = 0;
			fzqzzf = 0.0;
			xmzf = 0.0;
			if (null != erModelListList && erModelListList.size() > 0) {
				for (int i = 0; i < erModelListList.size(); i++) {
					sortPosition = this.getSortPosition(erModel
							.getBasicInfoId(), erModelListList.get(i));
					if (-1 != sortPosition) {
						alreadyExpertCount++;
						totalSortPosition = totalSortPosition + sortPosition;
						fzqzzf = fzqzzf
								+ erModelListList.get(i).get(
										erModelListList.get(i).size()
												- sortPosition).getFzqzzf();
						xmzf = xmzf
								+ erModelListList.get(i).get(
										erModelListList.get(i).size()
												- sortPosition).getXmzf();
					}
					// System.out.println("------项目id：
					// "+erModel.getBasicInfoId());
					// System.out.println("排序分： "+sortPosition);
					// System.out.println("--------------------------------------------------");
				}
			}
			erModel.setAlreadyReviewExpertCount(new Integer(alreadyExpertCount)
					.toString());// 设置已经复审评分的专家数
			if (0 != alreadyExpertCount) {
				erModel.setXmpxpjf(this
						.getTwoDecimal((double) (totalSortPosition)
								/ (double) alreadyExpertCount));
				erModel.setXmzzpjf(this.getTwoDecimal(fzqzzf
						/ alreadyExpertCount));
				erModel.setXmpjf(this.getTwoDecimal(xmzf / alreadyExpertCount));
			} else {
				erModel.setXmpxpjf(0.0);
				erModel.setXmzzpjf(0.0);
				erModel.setXmpjf(0.0);
			}
			erModel.setFzqzzf(fzqzzf);
			erModel.setXmzf(xmzf);
			if (null == this.review2DAO.findReviewResultsByZlid(erModel
					.getBasicInfoId())) {
				erModel.setState("0");// 判断如果复审结果表中不存在该条项目信息，则将复审审核标志置为0
			} else {
				erModel.setState("1");// 否则将复审审核标志置为1
			}
			erModelList.add(erModel);
		}
		return this.sortList(erModelList);
	}

	// /**
	// * 根据条件查找复审分数表中的数据，并经过一定的运算返回复审分数model列表
	// */
	// public List<ExpertsReviewModel2> findReviewXmFsList(String hqlWhere) {
	// List resultList = this.review2DAO.findReviewXmFsList(hqlWhere);//
	// 根据条件查找复审分数表中的数据
	// Iterator it = resultList.iterator();// 获得迭代器
	// List<ExpertsReviewModel2> erModelList = new
	// ArrayList<ExpertsReviewModel2>();
	// List<String> basicInfoIdList = new ArrayList<String>();
	// while (it.hasNext()) {
	// Object[] result = (Object[]) it.next();
	// ExpertsReviewModel2 erModel = new ExpertsReviewModel2();
	// erModel.setBasicInfoId(result[0].toString());// 存入项目id
	// erModel.setBasicInfoName(result[1].toString());// 存入项目名称
	// erModel.setZlqr(result[2].toString());// 存入专利权人
	// erModel.setXkName(result[3].toString());// 存入学科名称
	// erModel.setAlreadyReviewExpertCount(result[4].toString());// 存入已评专家数
	// erModel.setXmzf(this.getTwoDecimal(new Double(result[5].toString())));//
	// 存入项目总分
	// erModel.setXmpjf(this.getTwoDecimal(new Double(result[6].toString())));//
	// 存入项目平均分
	// erModel.setFzqzzf(this.getTwoDecimal(new
	// Double(result[7].toString())));// 存入项目分值权重总分
	// erModel.setXmzzpjf(this.getTwoDecimal(new
	// Double(result[8].toString())));// 存入项目分值权重平均分
	// erModel.setYear(result[9].toString());// 存入评审年份
	// if (null != result[10] && result[10].toString().length() > 0) {
	// erModel.setState(result[10].toString());// 判断审核标志，如果不为空，则存入评审标志
	// } else {
	// erModel.setState("0");// 如果审核标志为空，则将审核标志置为0
	// }
	// erModelList.add(erModel);
	// basicInfoIdList.add(erModel.getBasicInfoId());
	// }
	// String hql = hqlWhere.replaceAll("xmfs", "xmjg");// 将hqlWhere中的表别名更改
	//
	// List<TblXmjg1> xmjg1List = this.review1DAO.findReviewXmJgList(hql);//
	// 根据条件查找初审结果表中的项目信息
	// if (null != xmjg1List && xmjg1List.size() > 0) {// 判断如果项目列表不为空
	// for (TblXmjg1 xmjg1 : xmjg1List) {
	//
	// ExpertsReviewModel2 erModel = new ExpertsReviewModel2();//
	// 新建一个ExpertsReviewModel2
	// erModel.setBasicInfoId(xmjg1.getBasicinfo().getZlid());// 存入项目id
	// erModel.setBasicInfoName(xmjg1.getBasicinfo().getName());// 存入项目名称
	// erModel.setZlqr(xmjg1.getBasicinfo().getZlqr());// 存入专利权人
	// erModel.setXkName(xmjg1.getBasicinfo().getXk().getName());// 存入学科名称
	// erModel.setAlreadyReviewExpertCount("0");// 将已复审专家数置为0
	// if (null == this.review2DAO.findReviewResultsByZlid(erModel
	// .getBasicInfoId())) {
	// erModel.setState("0");// 判断如果复审结果表中不存在该条项目信息，则将复审审核标志置为0
	// } else {
	// erModel.setState("1");// 否则将复审审核标志置为1
	// }
	// if (!this.isExitInArray(xmjg1.getBasicinfo().getZlid(),
	// basicInfoIdList))// 判断如果该条项目信息没有进行复审，则将该项目信息存入返回的list
	// {
	// erModelList.add(erModel);
	// }
	// }
	// }
	// return erModelList;
	// }

	/**
	 * 保存或者更新复审结果表
	 */
	public boolean saveOrUpdateTblXmjg2(XmReviewResults2 xmReviewResults2,
			String jydjId) {
		TblXmjg2 xmjg2 = BeanAndModelConverter
				.getTblXmjg2ByXmReviewResults2(xmReviewResults2);// 将复审结果表model转化复审结果表bean，即将xmReviewResults2转化为xmjg2
		if (null != jydjId && !"".equals(jydjId)) {// 如果建议等级不为空
			xmjg2.setSysXmpsdj(this.baseDataDAO.findXmpsdj(jydjId));// 存入建议等级
		}

		TblXmjg2 tblXmjg2 = (TblXmjg2) this.review2DAO
				.findReviewResultsByZlid(xmjg2.getBasicinfo().getZlid());// 根据项目id查找复审结果表中的唯一一条记录，并赋予一个对象
		if (null == tblXmjg2) {// 判断该对象是否为空
			this.review2DAO.saveReviewsResults(xmjg2);// 如果为空则保存一个新对象
			this.review2DAO.updateReviewsState(xmjg2.getBasicinfo().getZlid(),
					"1");
			return true;
		} else {// 否则
			tblXmjg2.setXmzf(xmjg2.getXmzf());
			tblXmjg2.setXmpjf(xmjg2.getXmpjf());
			tblXmjg2.setBasicinfo(xmjg2.getBasicinfo());
			tblXmjg2.setSysXmpsdj(xmjg2.getSysXmpsdj());
			tblXmjg2.setPsrq(xmjg2.getPsrq());
			tblXmjg2.setUsername(xmjg2.getUsername());
			tblXmjg2.setYear(xmjg2.getYear());
			this.review2DAO.updateReviewsResults(tblXmjg2);// 将数据转存入现有对象，更新数据库记录
			this.review2DAO.updateReviewsState(tblXmjg2.getBasicinfo()
					.getZlid(), "1");
			return true;
		}

	}

	/**
	 * 通过项目id，学科id查找符合条件的专家列表
	 */
	public List<ExpertModel> listReviewExpertByBasicInfoId(String basicInfoId,
			String xkId, String hqlWhere) {
		List<TblZhuanjiarukuxinxibiao> tzjList = this.review2DAO
				.listReviewExpertByBasicInfoId(basicInfoId);// 列出复审分数表中的专家列表
		List<String> expertIdList = new ArrayList<String>();// 构造一个list，存入复审分数表中的专家列表中的专家id
		for (TblZhuanjiarukuxinxibiao tzj : tzjList) {
			expertIdList.add(tzj.getFBh().toString());
		}

		List<TblZjpsfp> zjpsfpList;
		if (!"".equals(xkId) && xkId.length() > 0) {
			zjpsfpList = this.getZjpsfpDAO().listZjpsfpByXmpsmcId(
					SysParameter.SECONDREVIEW, xkId, hqlWhere);// 判断如果学科id不为空，则查找出复审对应学科的已分配列表
		} else {
			zjpsfpList = this.getZjpsfpDAO().listZjpsfpByXmpsmcId(
					SysParameter.SECONDREVIEW, hqlWhere);// 判断如果学科为空，则查找复审对应的已分配列表
		}
		List<ExpertModel> emList = new ArrayList<ExpertModel>();
		for (TblZjpsfp zjps : zjpsfpList) {// 循环分配列表
			ExpertModel em = BeanAndModelConverter.getExpertModel(zjps
					.getTblZhuanjiarukuxinxibiao());
			if (this.isExitInArray(em.getFBh().toString(), expertIdList))// 如果该分配列表中的专家已经进行了复审，则将复审标志置为true
			{
				em.setAlreadySecondReview(true);
			}
			emList.add(em);
		}
		return emList;
	}

	/**
	 * 通过项目id查找复审结果
	 */
	public XmReviewResults2 findXmReviewResults2ByXmId(String xmId) {
		TblXmjg2 xmig2 = (TblXmjg2) this.review2DAO
				.findReviewResultsByZlid(xmId);
		return BeanAndModelConverter.getXmReviewResults2ByTblXmjg2(xmig2);
	}

	/**
	 * 列出复审结果表中的数据
	 */
	@SuppressWarnings("unchecked")
	public PagerModel listReview2Result(String hqlWhere) {
		PagerModel pagerModel = this.getReview2DAO().findReviewResultsPageList(
				hqlWhere);
		List<TblXmjg2> xmjg2List = (List<TblXmjg2>) pagerModel.getDatas();
		List<XmReviewResults2> xmReviewResults2List = new ArrayList<XmReviewResults2>();
		PagerModel pm = new PagerModel();
		pm.setTotal(pagerModel.getTotal());
		for (TblXmjg2 xmjg2 : xmjg2List) {
			XmReviewResults2 xmReviewResults2 = BeanAndModelConverter
					.getXmReviewResults2ByTblXmjg2(xmjg2);
			xmReviewResults2List.add(xmReviewResults2);
		}
		pm.setDatas(xmReviewResults2List);
		return pm;
	}

	/**
	 * 保存审核结果
	 */
	public void saveReviewsResults(Object o) {
		this.getReview2DAO().saveReviewsResults(o);

	}
    /**
     * 导出复审分数信息
     */
	public File exportSecondReviewFs(String fileName,
			List<ExpertsReviewModel2> erm2List) {
		File exportFile = null;
		if (!"".equals(fileName) && fileName.length() > 0) {
			try {
				exportFile = new File(fileName);
				if (!exportFile.exists()) {
					exportFile.createNewFile();
				}
				FileOutputStream os = new FileOutputStream(exportFile);
				WritableWorkbook book = null;
				book = Workbook.createWorkbook(os);
				WritableSheet sheet1 = book.createSheet("复审分数信息", 0);// 设置第一个sheet的名称
				sheet1.getSettings().setTopMargin(1.0);// 设置页面顶边距,此长度与excel实际长度的转化公式：1：2.5
				sheet1.getSettings().setBottomMargin(1.0);// 设置页面底边距,此长度与excel实际长度的转化公式：1：2.5
				sheet1.getSettings().setLeftMargin(0.2);// 设置页面左边距,此长度与excel实际长度的转化公式：1：2.5
				sheet1.getSettings().setRightMargin(0.2);// 设置页面右边距,此长度与excel实际长度的转化公式：1：2.5
				/**
				 * 设置普通单元格样式
				 */
				WritableFont wf = new WritableFont(WritableFont.ARIAL, 12,
						WritableFont.NO_BOLD, false,
						UnderlineStyle.NO_UNDERLINE, Colour.BLACK);

				WritableCellFormat wcf = new WritableCellFormat(wf);
				wcf.setBackground(Colour.WHITE);// 设置背景色
				wcf.setAlignment(Alignment.CENTRE);// 设置水平对齐方式
				wcf.setVerticalAlignment(VerticalAlignment.CENTRE);// 设置垂直对齐方式
				wcf.setBorder(Border.ALL, BorderLineStyle.THIN);// 设置单元格边框样式
				wcf.setWrap(true);// 设置自动换行

				/**
				 * 设置表头样式
				 */
				WritableFont wfTitle = new WritableFont(WritableFont.ARIAL, 24,
						WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
						Colour.BLACK);

				WritableCellFormat wcfTitle = new WritableCellFormat(wfTitle);
				wcfTitle.setBackground(Colour.WHITE);// 设置背景色
				wcfTitle.setAlignment(Alignment.CENTRE);// 设置水平对齐方式
				wcf.setVerticalAlignment(VerticalAlignment.CENTRE);// 设置垂直对齐方式
				// wcfTitle.setBorder(Border.ALL,
				// BorderLineStyle.THIN);//设置单元格边框样式
				wcfTitle.setWrap(true);// 设置自动换行

				sheet1.setRowView(0, 800);
				sheet1.mergeCells(0, 0, 5, 0);// 合并单元格
				sheet1.addCell(new Label(0, 0, "初审分数信息列表", wcfTitle));
				// sheet1.getSettings().setFitToPages(true);
				sheet1.setColumnView(0, 8);// 设置列宽
				sheet1.addCell(new Label(0, 1, "序号", wcf));
				sheet1.setColumnView(1, 25);
				sheet1.addCell(new Label(1, 1, "项目名称", wcf));
				sheet1.setColumnView(2, 25);
				sheet1.addCell(new Label(2, 1, "专利权人", wcf));
				sheet1.setColumnView(3, 18);
				sheet1.addCell(new Label(3, 1, "专业组", wcf));
				sheet1.setColumnView(4, 10);
				sheet1.addCell(new Label(4, 1, "总分", wcf));
				sheet1.setColumnView(5, 15);
				sheet1.addCell(new Label(5, 1, "排序平均分", wcf));
				/**
				 * 循环输出单元格内容
				 */
				for (int i = 0; i < erm2List.size(); i++) {
					ExpertsReviewModel2 erm2 = erm2List
							.get(i);
					sheet1.addCell(new Label(0, i + 2, new Integer(i + 1)
							.toString(), wcf));
					sheet1.addCell(new Label(1, i + 2, erm2
							.getBasicInfoName(), wcf));
					sheet1.addCell(new Label(2, i + 2, erm2
							.getZlqr(), wcf));
					sheet1.addCell(new Label(3, i + 2, erm2
							.getXkName(), wcf));
					sheet1.addCell(new Label(4, i + 2,erm2.getFzqzzf().toString(),wcf));
					sheet1.addCell(new Label(5, i + 2,erm2.getXmpxpjf().toString(), wcf));
				}
				book.write();
				os.flush();
				book.close();
				os.close();
				return exportFile;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} catch (RowsExceededException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} catch (WriteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			} finally {

			}
		} else {
			return null;
		}
	}

	public IExpertsReviewDAO getReview2DAO() {
		return review2DAO;
	}

	public void setReview2DAO(IExpertsReviewDAO review2DAO) {
		this.review2DAO = review2DAO;
	}

	/**
	 * @return the review1DAO
	 */
	public IExpertsReviewDAO getReview1DAO() {
		return review1DAO;
	}

	/**
	 * @param review1DAO
	 *            the review1DAO to set
	 */
	public void setReview1DAO(IExpertsReviewDAO review1DAO) {
		this.review1DAO = review1DAO;
	}

	/**
	 * @return the baseDataDAO
	 */
	public BaseDataDAO getBaseDataDAO() {
		return baseDataDAO;
	}

	/**
	 * @param baseDataDAO
	 *            the baseDataDAO to set
	 */
	public void setBaseDataDAO(BaseDataDAO baseDataDAO) {
		this.baseDataDAO = baseDataDAO;
	}

	/**
	 * @return the zjpsfpDAO
	 */
	public IZjpsfpDAO getZjpsfpDAO() {
		return zjpsfpDAO;
	}

	/**
	 * @param zjpsfpDAO
	 *            the zjpsfpDAO to set
	 */
	public void setZjpsfpDAO(IZjpsfpDAO zjpsfpDAO) {
		this.zjpsfpDAO = zjpsfpDAO;
	}

	/**
	 * 判断一个字符串data是否在字符串列表datas中 如果在则返回true，否则返回false
	 * 
	 * @param data
	 * @param datas
	 * @return
	 */
	public boolean isExitInArray(String data, List<String> datas) {
		boolean bl = false;
		if (null == datas || datas.size() <= 0) {
			return false;
		}
		for (String i : datas) {
			if (data.equals(i)) {
				bl = true;
				break;
			}
		}
		return bl;
	}

	public int findCountReviewXmFsList(String hqlWhere) {
		// TODO Auto-generated method stub
		return 0;
	}

	public List findZhuanjiaByZlid(String zlid) {
		// TODO Auto-generated method stub
		return null;
	}

	public int findReviewXkId(String hql) {
		// TODO Auto-generated method stub
		return 0;
	}

	public Object findXmByZlid(String zlid) {
		ExpertsReviewModel2 erm2 = new ExpertsReviewModel2();
		Object[] o = (Object[]) this.review2DAO.findXmByZlid(zlid);
		if (null != o && o.length > 0) {
			erm2.setBasicInfoModel(BeanAndModelConverter
					.getBasicInfoModel((Basicinfo) o[0]));
			erm2.setXmzf(this.getTwoDecimal((Double) o[1]));
			erm2.setXmpjf(this.getTwoDecimal((Double) o[2]));
			erm2.setFzqzzf(this.getTwoDecimal((Double) o[3]));
			erm2.setXmzzpjf(this.getTwoDecimal((Double) o[4]));
		}
		return erm2;
	}

	public Integer findZjpsfpCountByXmpsmcId(String xmpsmcId, String zhuanyeId,
			String hqlWhere) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<ExpertsReviewModel2> findReviewXmFsListByZlId(String zlid,
			String hqlWhere) {
		List ls = this.getReview2DAO().listReviewFsList(zlid, hqlWhere);
		List<ExpertsReviewModel2> ermList = new ArrayList<ExpertsReviewModel2>();
		Iterator it = ls.iterator();
		while (it.hasNext()) {
			Object[] obj = (Object[]) it.next();
			ExpertsReviewModel2 erm = new ExpertsReviewModel2();
			erm.setExpertModel(BeanAndModelConverter
					.getExpertModel((TblZhuanjiarukuxinxibiao) obj[0]));
			erm.setJydj(BeanAndModelConverter
					.getXmpsdjModelByXmpsdjBean((SysXmpsdj) obj[1]));
			erm.setXmzf((Double) obj[2]);
			erm.setXmpjf((Double) obj[3]);
			erm.setFzqzzf((Double) obj[4]);
			erm.setXmzzpjf((Double) obj[5]);
			ermList.add(erm);

		}
		return ermList;
	}

	public double getTwoDecimal(double oldDecimal) {
		BigDecimal b = new BigDecimal(oldDecimal);
		return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
	}

	/**
	 * 查找data在datas中的位置
	 * 
	 * @param data
	 * @param datas
	 * @return
	 */
	public int getSortPosition(String data, List<ExpertsReviewModel2> datas) {
		if (null == datas || datas.size() <= 0) {
			return -1;
		} else {
			for (int i = 0; i < datas.size(); i++) {
				if (data.equals(datas.get(i).getBasicInfoId())) {
					return datas.size() - i;
				}
			}
			return -1;
		}

	}

	/**
	 * 排序
	 * 
	 * @param oldList
	 * @return
	 */
	public List<ExpertsReviewModel2> sortList(List<ExpertsReviewModel2> oldList) {
		if (null != oldList && oldList.size() > 0) {
			List<ExpertsReviewModel2> tempList = oldList;
			ExpertsReviewModel2 tempErm;
			for (int i = 0; i < tempList.size(); i++) {
				Double maxFenshu = tempList.get(i).getXmpxpjf();
				ExpertsReviewModel2 maxBI = tempList.get(i);
				int maxId = i;
				for (int j = i + 1; j < tempList.size(); j++) {
					if (oldList.get(j).getXmpxpjf() > maxFenshu) {
						maxFenshu = tempList.get(j).getXmpxpjf();
						maxBI = tempList.get(j);
						maxId = j;
					}
				}
				tempErm = tempList.get(i);
				tempList.remove(i);
				tempList.add(i, maxBI);
				tempList.remove(maxId);
				tempList.add(maxId, tempErm);
			}
			return tempList;
		}
		return new ArrayList<ExpertsReviewModel2>();
	}

	public void saveOrUpdateReviews1(Object o) {
		// TODO Auto-generated method stub

	}

	public Integer findXmCountByXkId(String xkId) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer findFsCountByXkId(String xkId) {
		// TODO Auto-generated method stub
		return null;
	}

	public void saveOrUpdateTime(TblSystemparam t,TblSystemparam t2) {
		// TODO Auto-generated method stub
		
	}

}